#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/12/21 16:28
    Desc  :
--------------------------------------
"""
from mongoengine.base import TopLevelDocumentMetaclass


class QuerySetUtils:
    """
    Model对象的一些方法
    """
    def __init__(self, queryset):
        self.queryset = queryset

    def filterField(self, form:dict):
        """
        过滤非表结构字段的数据
        :param form:
        :return:
        """
        # 表字段列表
        fieldsList = []

        if isinstance(self.queryset, TopLevelDocumentMetaclass):
            for i in self.queryset._fields:
                fieldsList.append(i)

        for i in list(form.keys()):
            if i not in fieldsList:
                form.pop(i)

        return form